package com.hspedu.method;

/**
 * @author DL5O
 * @version 1.0
 */
public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.setName("大龙");
        t.setPriority(Thread.MIN_PRIORITY);//设置最小的优先级
        t.start();//启动子线程

        //主线程打印5 个hi, 然后我就中断 子线程的休眠
        for (int i = 0; i < 5; i++) {
            Thread.sleep(1000);
            System.out.println("hi " + (i+1));
        }

        System.out.println(t.getName() + " 线程的优先级 = " + t.getPriority());//1
        t.interrupt();//中断该线程，当执行到这里，就会中断，t线程的休眠

    }
}

class T extends Thread {//自定义的线程类

    @Override
    public void run() {
        while (true) {
            for (int i = 0; i < 20; i++) {
                System.out.println(Thread.currentThread().getName() + " 吃包子~~~" + (i + 1));
            }
            try {
                System.out.println("大龙休息中~~");
                Thread.sleep(20 * 1000);
            } catch (InterruptedException e) {
                //InterruptedException 是捕获到一个终端异常
                System.out.println(Thread.currentThread().getName() + "被 interrupt了");
            }
        }
    }
}

